package com.lyf.convert_x.strategy.dateStrategy;

import com.lyf.convert_x.utils.DateUtils;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Objects;

/**
 * @program: com.lyf.convert_x.strategy.dateStrategy
 * @description:
 * @author: GG-lyf
 * @create: 2024/10/29
 */
public class ToTimeStampSecondConverter implements DateConverterStrategy{
    @Override
    public String execute(String msg) {
        LocalDateTime localDateTime = DateUtils.convertToDateTime(msg);
        if (Objects.isNull(localDateTime)){
            return msg;
        }
        long timestampInSeconds = localDateTime.toEpochSecond(ZoneOffset.UTC);
        return String.valueOf(timestampInSeconds);
    }
}
